#include <math.h>

int iir_1st_order_narrowband_lowpass_filter(int xn)
{
     //The difference equation:y(n) = a0*x(n) + a1*x(n-1) + b0*y(n-1);
    static float yn_1 = 0.0;

    float yn = 0.02*xn +  0.98*yn_1;
    
    yn_1 = yn;
    
    return (int)yn;
}


int iir_biquad_filter(int xn)
{
    //The difference equation:y(n) = a0*x(n) + a1*x(n-1) + a2*x(n-2) - b1*y(n-1)-b2*y(n-2);
    
    static float xn_1 = 0.0, xn_2 = 0.0, yn_1 = 0.0, yn_2 = 0.0;
    
    float yn = 0.00022*xn + 0.00044*xn_1 + 0.00022*xn_2 + 1.9696*yn_1 - 0.9704*yn_2;
    
    xn_2 = xn_1;
    xn_1 = xn;
    yn_2 = yn_1;
    yn_1 = yn;
    
    return (int)yn;
}
